"""

Task that creates images.

"""

# Import schema modules
from tasks.operators import visualization_operator
from tasks.libs import constants as sc

# Import DEXEN modules
from dexen.user.libs import constants as dc
from dexen.user.libs import server_api

""" GLOBALS """
pop_api = server_api.PopAPIFactory()

def develop(individuals = None):
    """
    Task that:
        - gets the number of individuals to process from the server
        - downloads individuals from the server
        - creates an image each individual
        - adds the image to the individual
        - uploads the updated individuals back to the server
    """
    print "I am in visualization" 
    
    # Get the number of individuals to be processed for the global data saved
    # on the server. These numbers are set in the config function for this 
    # schema.
    count_for_visualization = pop_api.getGlobalData()[sc.VIZUALIZATION]
    
    # Download individuals
    individuals = pop_api.downloadLiveIndividuals(
        select = (sc.PHENOTYPE, ), 
        where = (
            (sc.PHENOTYPE, dc.NOT_EQUAL, None)
        ),
        count = count_for_visualization
    )
    
    # Apply the operator to all individuals
    visualization_operator.executeVizualization(individuals)
     
    # Upload individuals
    pop_api.uploadIndividuals(individuals)

